package com.xiaoyu.client.adapter.seek;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;

import com.techfansy.moreImageSelected.BitmapUtils;
import com.techfansy.moreImageSelected.bean.ImageItem;
import com.xiaoyu.client.R;
import com.xiaoyu.client.ui.activity.main.mine.my_info.FocusoncountActivity;
import com.xiaoyu.commonlib.utils.ToastUtil;

import java.util.List;

/**
 * @Author: JX
 * @Date: 2018/5/24 15:20
 * @Description:选择多张图片显示
 */

public class ForumAddAdapter extends BaseAdapter {

    private List<ImageItem> mList;
    private IDeleteImgListener mListener;

    public ForumAddAdapter(List<ImageItem> mList) {
        this.mList = mList;
    }

    @Override
    public int getCount() {
        return mList.size() ;
    }

    @Override
    public Object getItem(int position) {
        return mList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(final int position, View view, ViewGroup viewGroup) {
        ViewHolder viewHolder = null;
        if (view == null) {
            view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.select_img, null);
            viewHolder = new ViewHolder();
            viewHolder.mImgView = view.findViewById(R.id.item_select_imgs);
            viewHolder.mDeleteImg = view.findViewById(R.id.seleted_img_delete);
            view.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) view.getTag();
        }
        //获取显示选择完的照片
        if (mList != null && position < mList.size()) {
            ImageItem imageItem = mList.get(position);
            viewHolder.mImgView.setImageBitmap(BitmapUtils.getBitmap(imageItem.getPaths(), 300, 300));
            viewHolder.mDeleteImg.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    if (mListener != null) {
                        mListener.deleteImg(position);
                    }
                }
            });

        }
        return view;
    }

    class ViewHolder {
        private ImageView mImgView;
        private ImageView mDeleteImg;
    }

    public void upDataList(List<ImageItem> mList) {
        this.mList = mList;
        notifyDataSetChanged();
    }
    public interface IDeleteImgListener {
        void deleteImg(int position);
    }

    public void setIDeleteImg(IDeleteImgListener listener) {
        this.mListener = listener;
    }
}
